package shop.controls;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import shop.pojo.Goods;
import shop.services.GoodsServices;

/**
 * Servlet implementation class GoodsSel
 */
public class GoodsSel extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GoodsSel() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String strPage = request.getParameter("currentPage");
		int page = 0;
		if(strPage != null){
			page = Integer.parseInt(strPage);
		}		
		List<Goods> list = new GoodsServices().SelCurrentGoods(page*6);
		request.getSession().setAttribute("list", list);//当前页的商品的数据
		List<Goods> list1 = new GoodsServices().SelAllGoods();
		int size = list1.size();//总记录数
		int totalSize = size%6==0?size/6:size/6+1;//总页数
		request.getSession().setAttribute("size",size);//总记录数
		request.getSession().setAttribute("totalSize",totalSize-1);//总记页数
		request.getSession().setAttribute("page",page);//当前页
		request.getRequestDispatcher("jsp2/goodsList.jsp").forward(request, response);
	}

}
